<template>
    <view class="timoney">
        <view class="minela">
            <image class="leftimge" src="../../static/img/tethe.png"></image>
            <text>TRC20_USDT</text>
        </view>
        <view class="modtwo">
            <view class="bitile">
                提币地址
            </view>
            <view class="inps">
                <input v-model="toAddres" type="text" placeholder="请输入或长按粘贴地址" />
                <!-- #ifndef H5 -->
                <image @click="scancodefn" src="../../static/img/saom.png"></image>
                <!-- #endif -->
            </view>
            <view class="bitile">
                数量
            </view>
            <view class="inps">
                <input type="number" v-model="numbercont" placeholder="最小提币数量100.000000" />
                <text @click="kyMoney">全部</text>
            </view>
            <view class="bitile">
                手续费
            </view>
            <view class="inps">
                <view class='feepri'>
                    {{feepri}}
                </view>

                <text style="color: #6E6E6E;">USDT</text>
            </view>
            <view class="bitile">
                支付密码
            </view>
            <view class="inps">
                <input v-model="transPwds" type="text" placeholder="请输入支付密码" />
            </view>
            <view class="lastyps">
                最小提币数量：100.0000USDT，为保障资金安全，当
                你的账户账户安全策略变更、密码修改、我们会对提币
                进行人工审核
            </view>
            <view class="numberda">
                <text>到账数量</text>
                <text>{{numbercont}}USDT</text>
            </view>
        </view>
        <view class="timo" @click="tMonetFn">提币</view>
    </view>
</template>

<script>
    let uinfo;
    import request from "../../untils/request.js";
    export default {
        data() {
            return {
                numbercont: '',
                feepri: '',
                toAddres: '',
                yzcode: '',
                transPwds: '',
                codeBtn: {
                    codeTime: 60,
                    codeText: "获取验证码",
                    codeStatus: true,
                },
            }
        },
        onLoad() {
            uinfo = uni.getStorageSync('userInfo');
            this.sfee();
        },
        methods: {
            //扫一扫
            scancodefn(){
                let _this=this;
                console.log('222')
                uni.scanCode({
                    success: function (res) {
                        console.log('条码类型：' + res.scanType);
                        console.log('条码内容：' + res.result);
                        _this.toAddres=res.result;
                    },
                    fail:function(error){
                        uni.showToast({
                            icon: "none",
                            title: error,
                        });
                    }
                });
            },
            //提币
            tMonetFn() {
                if (this.toAddres == '') {
                    return uni.showToast({
                        icon: "none",
                        title: '请输入地址',
                    });
                }
                if (this.numbercont < 100) {
                    return uni.showToast({
                        icon: "none",
                        title: '最少为100',
                    });
                }
                if (this.numbercont == '') {
                    return uni.showToast({
                        icon: "none",
                        title: '请输入数量',
                    });
                }
                if (this.transPwds == '') {
                    return uni.showToast({
                        icon: "none",
                        title: '请输入支付密码',
                    });
                }
                uni.showLoading({
                    mask:true
                });
                //提交接口
                request.postAssets('/assets/userWallet/withdraw', {
                    chainName: 'TRON',
                    coinName: 'usdt',
                    finalAmount: this.numbercont,
                    fromAddress: uinfo.userWalletInfo.address,
                    transPwd: this.transPwds, //支付密码
                    //verifyCode: this.yzcode, //验证码
                    targetAddress: this.toAddres,
                    userId: uinfo.userId,
                }).then(res => {
                    if (res.code == '200') {
                        uni.hideLoading();
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                        uni.switchTab({
                            url: '/pages/mine/mine',
                        });
                    } else {
                        uni.hideLoading();
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                    }
                })
            },
            //获取验证码
            getPhonecode() {
                //0手机号，1邮箱
                let telEmail = '0';
				let accountNumber;
                if (uinfo.userLoginInfo.email == null) {
                    telEmail = '0';
					accountNumber = uinfo.userLoginInfo.mobile;
                } else {
                    telEmail = '1';
					accountNumber = uinfo.userLoginInfo.email;
                }
                if (this.codeBtn.codeStatus) {
                    this.codeBtn.codeStatus = false;
                    let timerId = setInterval(() => {
                        let codetime = this.codeBtn.codeTime;
                        codetime--;
                        this.codeBtn.codeTime = codetime;
                        this.codeBtn.codeText = "剩余" + codetime + "秒";
                        if (codetime < 1) {
                            clearInterval(timerId);
                            this.codeBtn.codeText = "重新获取";
                            this.codeBtn.codeTime = 60;
                            this.codeBtn.codeStatus = true;
                        }
                    }, 1000);
                    request.postMember('/user/login/sendVerifiyCode', {
                        accountNumber: uinfo.userLoginInfo.mobile,
                        businessType: '3',
                        accountType: telEmail
                    }).then(res => {
                        console.log(res)
                        if (res.code == "200") {
                            
                            uni.showToast({
                                icon: "none",
                                title: '发送成功',
                            });
                        } else {
                            uni.showToast({
                                icon: "none",
                                title: res.message,
                            });
                        }
                    })
                }
            },
            sfee() {
                //手续费接口//tx_fee:交易手续费
                request.postAssets('/assets/userWallet/queryDataDictionary', {
                    key: 'tx_fee'
                }).then(res => {
                    //console.log(res)
                    if (res.code == '200') {
                        this.feepri = res.data.value;
                    }
                })
            },
            //获取可用金额
            kyMoney() {
                request.postAssets('/assets/userWalletInfo/queryUserWalletInfo', {
                    sortAttribute: '3',
                    sortType: 'descend',
                    userId: uinfo.userId
                }).then(res => {
                    if (res.code == '200') {
                        this.numbercont = res.data.items[0].avaliableBalance;
                    }
                })
            }
        }
    }
</script>

<style>
    .timoney {
        padding: 20px 0 50px 0;
        background-color: #F5F5F5;
    }

    .minela {
        width: 680rpx;
        height: 108rpx;
        padding: 0 0 0 20px;
        background: #FFFFFF;
        margin: 0 auto 20rpx;
        border-radius: 6px;
        display: flex;
        align-items: center;
    }

    .minela .leftimge {
        width: 60rpx;
        height: 60rpx;
        margin: 0 10rpx 0 0;
    }

    .minela text {
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 500;
        color: #333333;
    }

    .modtwo {
        width: 710rpx;
        background-color: #FFFFFF;
        border-radius: 8px;
        margin: 0 auto;
        padding: 10px 0 0 0;
    }

    .modtwo .bitile {
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 27px;
        color: #333333;
        margin: 10px 10px 15px;
    }

    .modtwo .inps {
        border-bottom: 1px solid #EBEBEB;
        display: flex;
        margin: 0 10px;
        padding: 0 0 15px 0;
        justify-content: space-between;
    }

    .modtwo .inps .feepri {
        font-size: 14px;
    }

    .modtwo .inps input {
        font-size: 14px;
        width: 400rpx;
    }

    .modtwo .inps image {
        width: 20px;
        height: 20px;
    }

    .modtwo .inps text {
        font-size: 14px;
        font-family: Source Han Sans CN;
        font-weight: 500;
        line-height: 24px;
        color: #7F6AC3;
    }

    .modtwo .lastyps {
        font-size: 14px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 20px;
        color: #838AA4;
        margin: 20px 10px 40px;
    }


    .modtwo .numberda {
        font-size: 14px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 20px;
        color: #333333;
        margin: 0 10px;
        display: flex;
        justify-content: space-between;
        padding: 0 0 30px 0;
    }

    .timo {
        font-size: 14px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 38px;
        color: #FFFFFF;
        width: 710rpx;
        height: 38px;
        background: #7F6AC3;
        border-radius: 19px;
        text-align: center;
        margin: 40px auto 0;
    }
</style>
